<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<meta http-equiv="X-UA-Compatible" content="ie=edge">
		<meta name="format-detection" content="telephone=no" />
		<title>预约</title>
		<link rel="stylesheet" type="text/css" href="../css/style.css?v=1.0"/>
		<link rel="stylesheet" type="text/css" href="css/reser.css?v=1.0"/>
		<script type="text/javascript" src="../js/jquery-1.8.3.min.js?v=1.0"></script>
		<script type="text/javascript" src="../layer-mobile/layer.js?v=1.0"></script>
		<script type="text/javascript" src="../js/flexible.js?v=1.0"></script>
	</head>
	<body style="background: #F9F9F9;">
		<div class="reser">
			<div class="content"></div>
			<div class="asider">
				<button id="button" class="button" />预约</button>
				<div class="box">
					<p>距结束仅剩</p>
					<div class="timer" id="time"></div>
				</div>
			</div>
		</div>
		
		
		<script type="text/javascript">
			$(function(){
				
				var activeTo = '';
				var activeArry = [];
				//获取userid、goodid
				var userid = getQueryString('userId');
				var goodid = getQueryString('ktGoodId');
				
				//获取信息
				$ajax(
					url+'getKTGoodDetailById.ashx',
					'post',
					{ktGoodId:goodid,userid:userid},
					function(data){
						var detail = data.data.goodsDetail;
						if(detail){
							$('.content').html(detail.Content);
							activeTo = detail.ActiveTo;

							activeArry = activeTo.split(' ');
							var y = Number(activeArry[0].split('/')[0]),
								m = Number(activeArry[0].split('/')[1]),
								d = Number(activeArry[0].split('/')[2]),
								h = Number(activeArry[1].split(':')[0]),
								f = Number(activeArry[1].split(':')[1]),
								s = Number(activeArry[1].split(':')[2]);

							//倒计时 
							var oTime = document.getElementById('time');
							leftTimer(y,m,d,h,f,s,'oTime');
							
							$('#button').removeClass('gray');
							if(detail.IsOrdered.toUpperCase() == 'TRUE'){
								$('#button').html('已预约');
								$('#button').attr('disabled','disabled');
								$('#button').addClass('gray');
							}else if(new Date(activeTo) - new Date() <= 0){
								$('#button').attr('disabled','disabled');
								$('#button').addClass('gray');
								$('#button').html('已结束');
							}
						}else{
							layer.open({
								type: 2,
								content: '加载中',
								shadeClose: false
							});
						}
					},
					function(data){
						layer.open({
							content: '未登录，请先登录',
							btn: '我知道了'
						});
					}
				);
				
				if($('#time').html() == '已完成'){
					$('#button').attr('disabled','disabled');
					$('#button').addClass('gray');
				}
				
				$('#button').click(function(){
					if(userid == null){
						layer.open({
							content: '未登录，请先登录',
							btn: '我知道了'
						});
					}else{
						$ajax(
							url+'saveKTGoodsOrder.ashx',
							'post',
							{ktGoodId:goodid,userid:userid},
							function(data){
								layer.open({
									content: data.msg,
									skin: 'msg',
									time: 2
								});
								setTimeout(function () {
                                    location.reload();
                                }, 2000);
							},
							function(data){
								layer.open({
									content: '未登录，请先登录',
									btn: '我知道了'
								});
							}
						)
					}
					
				})
				
			})
			
		</script>
	</body>
</html>